package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.service.AdminBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Tangyin
 * @description：商场管理：品牌制造商
 * @since 2022/05/06 14:24
 */

@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {
    @Autowired
    AdminBrandService adminBrandService;

    @GetMapping("list")
    public BaseRespVo Brand(Integer id, String name, BaseParam param) {
        BrandData brandData = adminBrandService.query(param, id, name);
        return BaseRespVo.ok(brandData);
    }

    @RequestMapping("create")
    public BaseRespVo brandcreat(@RequestBody Brand brand) {
        int i = adminBrandService.createBrand(brand);
        return BaseRespVo.ok(i);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody Brand brand) {

        Brand newBrand = adminBrandService.update(brand);

        return BaseRespVo.listOk(newBrand);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Brand brand) {

//        adminBrandService.deleteBrand(brand);
//        int i=adminBrandService.deleteBrand(id);
        Integer i = adminBrandService.deleteBrandById(brand.getId());
        if (i == 1) {
            return BaseRespVo.ok(brand);
        }
        return BaseRespVo.invalidData();
    }
}
